//
//  WH_HomeTableViewCell.m
//  App_6.23
//
//  Created by wanghao on 16/6/27.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "WH_HomeTableViewCell.h"
#import "WH_HomeCollectionCell.h"

@interface WH_HomeTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *myCollectionV;


@end
@implementation WH_HomeTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self){
        
        [self createSubs];

    }
    return self;
}

-(void)createSubs{

    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
    //设置item 与四周的边界的距离 上左下右
    flowlayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    //设置每个itm大小
    flowlayout.itemSize = CGSizeMake(SCREEN_WIDTH/2, SCREEN_WIDTH/2+100);
    flowlayout.minimumLineSpacing = 0;
    flowlayout.minimumInteritemSpacing = 0;
    //flowlayout.sectionFootersPinToVisibleBounds = YES;
    self.myCollectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH/2+100) collectionViewLayout:flowlayout];
    self.myCollectionV.delegate = self;
    self.myCollectionV.dataSource = self;
    self.myCollectionV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_myCollectionV];
    [self.myCollectionV registerClass:[WH_HomeCollectionCell class] forCellWithReuseIdentifier:@"WH_HomeCollectionCell"];
    
}
#pragma mark - UICollectionView 协议代理方法

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    
    return self.cellArr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *indexC = @"WH_HomeCollectionCell";

    WH_HomeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:indexC forIndexPath:indexPath];
    cell.cellHome = self.cellArr[indexPath.item];
    return cell;
        
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    WH_Home *homeM = self.cellArr[indexPath.item];
    [self.homeDelegate pushDetailVC:homeM];
    
}

-(void)setCellArr:(NSMutableArray *)cellArr{
    
    if (_cellArr != cellArr) {
        
        _cellArr = cellArr;
    }
    [self.myCollectionV reloadData];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
